package ig.util;

import ig.metrica.ui.PantallaSevinproPanel;
import java.awt.Component;
import java.awt.Color;
import java.awt.Container;
import java.util.List;
import javax.swing.table.TableCellRenderer;
import javax.swing.JTable;

public class CellRenderSelectModel extends javax.swing.JLabel implements TableCellRenderer{

    public CellRenderSelectModel(){
        setOpaque(true);
        setBackground(Color.WHITE);
        setFont(new java.awt.Font("Dialog", 0, 12));        
    }

    public PantallaSevinproPanel getPantallaSevinproPanel(Container container){
        if(container != null){
            if(container instanceof PantallaSevinproPanel){
                return (PantallaSevinproPanel)container;
            }else{
                return  getPantallaSevinproPanel(container.getParent());
            }
        }
        return null;
    }
    public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column){
        CellRenderSelectModel model = new CellRenderSelectModel();
        Container container = getPantallaSevinproPanel(table.getParent());
        if ( container!=null && value!=null ){
            List list = ((PantallaSevinproPanel)container).getKeyAdd();
            if( column == 0 && list.size()>0 ){
                String[] keys = value.toString().split(":");
                String key = keys.length > 1 ? keys[1].trim() : keys[0].trim();
                //System.out.println(value.getClass());
                /*if( isSelected ){
                    System.out.println("key |" + key +"| in |" +list );
                }*/
                if(list.contains(value.toString()) || list.contains(key)){
                    model.setBackground(Color.YELLOW);
                }//Class.forName(key)
            }
            model.setText(value.toString());
        }
        if(isSelected){
            model.setForeground(Color.WHITE);
            model.setBackground(Color.BLUE);
            //System.out.println(container);
        }
        //if(value!=null)
        return model;
    }
}